package com.chis.mybatisplus.test;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.chis.mybatisplus.entity.User;
import com.chis.mybatisplus.entity.mapper.UserExtMapper;
import com.chis.mybatisplus.entity.mapper.UserMapper;

import javax.annotation.Resource;
import java.util.List;

/**
 * 
 * @Description 
 * @Company zwx
 * @author wlj
 * @version 2019年07月26日
 */
public class Service {
    @Resource
    protected UserMapper userMapper;
    @Resource
    protected UserExtMapper userExtMapper;

    public void testSave(){
        User user = new User();
        user.setId(1);
        user.setName("王列军");
        user.setAge(28);
        user.setEmail("wallege.163.com");
        userMapper.insert(user);
    }

    public void testUpdate(){
        User user = new User();
        user.setId(1);
        user.setAge(29);
        userMapper.updateById(user);
    }

    public User testFind(){
        return userMapper.selectById(1);
    }

    public List<User> testFindCondition(){
        return userMapper.selectList(new EntityWrapper<User>().eq("name", "王列军"));
    }

    public List<User> testPage(){
        return userMapper.selectPage(
                new Page<User>(1, 10),
                new EntityWrapper<User>().eq("name", "王列军").between("age", "18", "30")
        );
    }

    public User testExt(){
        return userExtMapper.testSelect(1);
    }


}
